<template>
  <div class="ad-form">
    <el-form size="mini" inline label-position="right" label-width="auto" ref="form" :model="form" v-loading="loading" :disabled="isDisableForm">
      <el-form-item prop="createUser" :rules="[{required: true, message: '请选择'}]">
        <ad-select placeholder="请选择业务员" v-model="form.createUser" :options="sellerData" size="medium"
                   :config="{optionKey: 'nickName', optionValue: 'id'}"/>
      </el-form-item>
    </el-form>
    <div class="op">
      <el-button type="primary" :loading="saving" @click="save">确 定</el-button>
      <el-button type="primary" plain @click="$emit('update:visible', false)">取 消</el-button>
    </div>
  </div>
</template>

<script>
import AdSelect from '@/components/AdSelect'
import adForm from '@/mixins/adForm'
import { getList as getSellerList } from '@/api/seller'
import { get as getLinkman, changeSeller as add } from '@/api/relation/linkman'

export default {
  components: {AdSelect},
  mixins: [adForm({add})],
  data() {
    return {
      sellerData: [],
      form: {
        createUser: ''
      }
    }
  },
  created() {
    getSellerList().then(res => {
      this.sellerData = res.data
    })
  },
  watch: {
    '$attrs.visible': {
      immediate: true,
      handler(visible) {
        if (visible) {
          getLinkman({id: this.$attrs.id}).then(res => {
            this.form.id = res.data.id
            this.$set(this.form, 'createUser', res.data.createUser)
          })
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.ad-form { display: flex; height: 140px; flex-direction: column;
  .el-form { display: flex; flex: 1; padding: 0 50px; align-items: center; }
  .op { margin-top: 0; }}
</style>